<template>
	<view class="my-recruitment-container">
		<view class="list" v-if="list.length!==0">
			<view class="list-scroll-container">
				<!-- scrolltolower事件可以监听加载到底部 -->
				<scroll-view scroll-y="true" class="list-scroll" @scrolltolower="loadMore">
					<view v-for="(item,index) in list" :key="index">
						<view class="list-card">
							<view @click="goDetail(item._id)">
								<view class="list-card-top">
									<view>{{item.title}}</view>
									<view class="status">{{item.status}}</view>
								</view>
								<view class="list-card-middle">
									<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000">
										<swiper-item v-for="(demo,id) in item.imgArr" :key="id">
											<image :src="demo" mode=""></image>
										</swiper-item>
									</swiper>
								</view>
								<view class="list-card-bottom">
									<view class="article-type">
										{{item.province}}
									</view>
									<view class="browser-number">
										{{item.scan}} 浏览
									</view>
								</view>
							</view>
						</view>
					</view>
					<uni-load-more v-if="(list.length===0 || list.length > 5) && isShowLoadMore"
						:status="loadData || 'loading'"></uni-load-more>
				</scroll-view>
			</view>
		</view>
		<view class="no-data" v-else>
			暂无发布的招募活动
		</view>
	</view>
</template>

<script>
	import {mapState} from "vuex";
	import {
		getInfo
	} from "../../ajax/api/home.js";
	export default {
		data() {
			return {
				current: 1,
				pageSize: 5,
				list: [],
				loadData: "loading",
				isShowLoadMore: true,
			}
		},
		computed:{
			...mapState(["qiyeData"])
		},
		async onShow(){
			// #ifdef MP-WEIXIN
			if (wx.hideHomeButton) {
				wx.hideHomeButton();
			}
			// #endif
			const res = await getInfo({
				current: this.current,
				pageSize:this.pageSize,
				enterprise:this.qiyeData._id
			})
			this.list = res.rows;
			if(this.list.length){
				this.list.forEach((item)=>{
					if(item.status === 0){
						item.status = "待审核"
					}else if(item.status === 1){
						item.status = "审核不通过"
					}else{
						item.status = "审核通过"
					}
				})
			}
		},
		methods: {
			async loadMore() {
				this.isShowLoadMore = true;
				this.current++;
				const res = await getInfo({
					current: this.current,
					pageSize: this.pageSize,
					enterprise:this.qiyeData._id
				})
				this.list.push(res.rows);
				this.isShowLoadMore = false;
				if (res.count === list.length) {
					// 全部数据加载完成
					this.loadData = "no-more";
				}
			},
			// 查看详情
			goDetail(id){
				this.$Router.push({
					path:"/pages/detail/detail",
					query:{
						id,
						isQiye:true,
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
@import "./css/myRecruitment.scss";
</style>
